﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace FCDB.Entity
{
    public class StaticObjectContextManager<T> : ObjectContextManager<T> where T : DbContext, new()
    {
        public StaticObjectContextManager()
        {
        }
        private static T _objectContext;
        private static object _lockObject = new object();

        public override T DbContext
        {
            get
            {
                lock (_lockObject)
                {
                    if (_objectContext == null)
                    {
                        string connectionString = ObjectContextHelper.GetEntityConnectionString();
                        _objectContext = Activator.CreateInstance(typeof(T), new object[] { connectionString }) as T;
                    }
                }
                return _objectContext;
            }
        }
    }
}
